﻿using System.Drawing;
using System.Globalization;
using System.Web;

namespace WebImageResizer.Filters
{
	internal class ZoomFilter : IImageFilter
	{
		#region IImageFilter Members

		public bool Process(HttpContext context, ref Bitmap bitmap)
		{
			string zoomParameter = context.Request["zoom"];
			if (string.IsNullOrEmpty(zoomParameter))
			{
				return false;
			}
			
			float zoomFactor;
			if (float.TryParse(zoomParameter, NumberStyles.Float, CultureInfo.InvariantCulture, out zoomFactor))
			{
				IImageTool imageTool = Factory.GetImageTool();
				bitmap = imageTool.Zoom(bitmap, zoomFactor);
				return true;
			}

			return false;
		}

		#endregion
	}
}